#include "ftestywelcome.h"
#include "ui_ftestywelcome.h"

FtestyWelcome::FtestyWelcome(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FtestyWelcome)
{
    ui->setupUi(this);
    this->initScore = -1;
    this->penalty = -1;
    setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    connect(this,SIGNAL(rejected()),this,SLOT(windowClose()));
}

FtestyWelcome::~FtestyWelcome()
{
    delete ui;
}

void FtestyWelcome::on_loadQuestionsButton_clicked()
{
    QSettings settings;
    QString dir = "";
    this->initScore = ui->initScoreSpinBox->value();
    this->penalty = ui->penaltySpinBox->value();
    this->ignoreSession = ui->ignoreSessionCheck->isChecked();
    QVariant lastdir = settings.value("lastdir");
    if (!lastdir.isNull())
        dir = lastdir.toString();
    this->fileName = QFileDialog::getOpenFileName(this,
                        tr("Otwórz plik z pytaniami"),
                        dir,
                        tr("Pliki tekstowe (*.txt);; Wszystkie pliki (*)"));
    if (!fileName.isEmpty()) {
        settings.setValue("lastdir", fileName);
        accept();
    }
}

void FtestyWelcome::windowClose() {
    exit(0);
}
